﻿/*
 Data : 3/10/2011
 Author: Rafael (T-IT).
 
 */
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Specialized;
using Microsoft.SharePoint.WebControls;
using System.Data;
using Data.BioTecnologia.Properties;

namespace Presentation.ABDI.WebPart.VWPInscritos
{
    public partial class VWPInscritosUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #region Button Controls

        protected void btnInscritos_Click(object sender, EventArgs e)
        {
            CarregarListaInscritos();
        }

        #endregion

        #region Métodos

        private void CarregarListaInscritos()
        {
            string htmlConteudo = string.Empty;
            string[] arrayItensList = checkBoxInscritos.Items.Cast<ListItem>()
                .Where(i => i.Selected == true)
                    .Select(i => i.Value).ToArray();

            SPSite mySite = SPContext.Current.Site;
            SPWeb myWeb = mySite.OpenWeb();
            SPList myList = myWeb.Lists[SharePointString.ListaInscritos]; // "Inscritos"];
            var collectionInscritos = myList.GetItems(arrayItensList).Cast<SPListItem>().ToList();


            htmlConteudo += "<table border='2'><tr>";
            foreach (string item in arrayItensList)
            {
                var itemName = checkBoxInscritos.Items.Cast<ListItem>().Where(i => i.Value.Equals(item)).Select(i => new { Text = i.Text }).ToList();
                htmlConteudo += string.Format(@"<td><b>{0}</b></td>", itemName[0].Text);
            }
            htmlConteudo += "</tr>";
            foreach (SPListItem itemLista in collectionInscritos)
            {
                htmlConteudo += "<tr>";
                foreach (string item in arrayItensList)
                {
                    htmlConteudo += string.Format("<td>{0}</td>", itemLista[item]);
                }
                htmlConteudo += "</tr>";

            }
            htmlConteudo += "</table>";
            divTable.InnerHtml = htmlConteudo;
        }

        #endregion 
    }
}
